import 'package:json_annotation/json_annotation.dart';

import 'item_style.dart';
import 'line_style.dart';
import 'text_style.dart';
import 'tooltip.dart';

part 'legend.g.dart';

@JsonSerializable(includeIfNull: false, explicitToJson: true)
class LegendData {
  var name;
  var icon;
  ItemStyle? itemStyle;
  ItemStyle? lineStyle;
  var textStyle;

  LegendData(
      {this.name, this.icon, this.itemStyle, this.lineStyle, this.textStyle});

  factory LegendData.fromJson(Map<String, dynamic> json) =>
      _$LegendDataFromJson(json);
  Map<String, dynamic> toJson() => _$LegendDataToJson(this);

}

@JsonSerializable(includeIfNull: false, explicitToJson: true)
class PageIcons {
  var horizontal; // image://url base64
  var vertical;

  PageIcons({this.horizontal, this.vertical}); // image://url base64

  factory PageIcons.fromJson(Map<String, dynamic> json) =>
      _$PageIconsFromJson(json);
  Map<String, dynamic> toJson() => _$PageIconsToJson(this);
}

@JsonSerializable(includeIfNull: false, explicitToJson: true)
class SelectorLabel {
  var show;
  var distance;
  var rotate; //-90 to 90
  var offset; //[30,40] move 30 horizontally and move 40 vertically.
  var color;
  var fontStyle;
  var fontWeight; //'normal' 'bold' 'bolder' 'lighter' 100 | 200 | 300 | 400...
  var fontFamily;
  var fontSize;
  var align; // left 'center'  'right'
  var verticalAlign; //'top' 'middle' 'bottom'
  var lineHeight;
  var backgroundColor;
  var borderColor;
  var borderWidth;
  var borderType;
  var borderDashOffset;
  var borderRadius;
  var padding;
  var shadowColor;
  var shadowBlur;
  var shadowOffsetX;
  var shadowOffsetY;
  var width;
  var height;
  var textBorderColor;
  var textBorderWidth;
  var textShadowColor;
  var textShadowBlur;
  var textShadowOffsetX;
  var textShadowOffsetY;
  var overFlow;
  var ellipsis; //Ellipsis to be displayed when overflow is set to truncate.
  var lineOverflow; //'truncate' Truncate the overflow lines.
  var rich;

  SelectorLabel(
      {this.show,
      this.distance,
      this.rotate,
      this.offset,
      this.color,
      this.fontStyle,
      this.fontWeight,
      this.fontFamily,
      this.fontSize,
      this.align,
      this.verticalAlign,
      this.lineHeight,
      this.backgroundColor,
      this.borderColor,
      this.borderWidth,
      this.borderType,
      this.borderDashOffset,
      this.borderRadius,
      this.padding,
      this.shadowColor,
      this.shadowBlur,
      this.shadowOffsetX,
      this.shadowOffsetY,
      this.width,
      this.height,
      this.textBorderColor,
      this.textBorderWidth,
      this.textShadowColor,
      this.textShadowBlur,
      this.textShadowOffsetX,
      this.textShadowOffsetY,
      this.overFlow,
      this.ellipsis,
      this.lineOverflow,
      this.rich});

  factory SelectorLabel.fromJson(Map<String, dynamic> json) =>
      _$SelectorLabelFromJson(json);
  Map<String, dynamic> toJson() => _$SelectorLabelToJson(this);
}

@JsonSerializable(includeIfNull: false, explicitToJson: true)
class LegendEmphasis {
  SelectorLabel? selectorLabel;

  LegendEmphasis({this.selectorLabel});
  factory LegendEmphasis.fromJson(Map<String, dynamic> json) =>
      _$LegendEmphasisFromJson(json);
  Map<String, dynamic> toJson() => _$LegendEmphasisToJson(this);
}

@JsonSerializable(includeIfNull: false, explicitToJson: true)
class Legend {
  var type;
  var id;
  var show;
  var zlvel;
  var z;
  var left; //'left', 'center', or 'right' 20 20%
  var top; //'top', 'middle', or 'bottom' 20 20%
  var right; //'auto' 20 20%
  var bottom; //'auto' 20 20%
  var width; //'auto' 20 20%
  var height; //'auto' 20 20%
  var orient;
  var align; //'auto' 'left' 'right'
  var padding;
  var itemGap;
  var itemWidth;
  var itemHeight;
  ItemStyle? itemStyle;
  LineStyle? lineStyle;

  var symbolSize;
  var symbolKeepAspect;
  var formatter;
  var selectedMode;
  var inactiveColor;
  var selected;
  TextStyle? textStyle;
  Tooltip? tooltip;
  var icon; //'circle', 'rect', 'roundRect', 'triangle', 'diamond', 'pin', 'arrow', 'none' image://url base64

  List<LegendData>? data;

  var backgroundColor;
  var borderColor;
  var borderWidth;
  var borderRadius;

  var shadowBlur;
  var shadowColor;
  var shadowOffsetX;
  var shadowOffsetY;

//设置为 legend.type is 'scroll' 可以起作用
  var scrollDataIndex;
  var pageButtonItemGap; //分页控制块中，按钮和页信息之间的间隔
  var pageButtonGap; //分页控制块与图例之间的间隔
  var pageButtonPosition; //分页控制块放置位置，'start'、 'end'
  var pageFormatter;
  PageIcons? pageIcons;
  var pageIconColor;
  var pageIconColorInactiveColor;
  var pageIconSize; //[15,3] 分页icon大小 左边15 右边3
  TextStyle? pageTextStyle;
  var animation;
  var animationDurationUpdate;

  LegendEmphasis? emphasis;

  var selector;

  SelectorLabel? selectorLabel;

  var selectorPosition;
  var selectorItemGap;
  var selectorButtonGap;

  Legend(
      {this.type,
      this.id,
      this.show,
      this.zlvel,
      this.z,
      this.left,
      this.top,
      this.right,
      this.bottom,
      this.width,
      this.height,
      this.orient,
      this.align,
      this.padding,
      this.itemGap,
      this.itemWidth,
      this.itemHeight,
      this.itemStyle,
      this.lineStyle,
      this.symbolSize,
      this.symbolKeepAspect,
      this.formatter,
      this.selectedMode,
      this.inactiveColor,
      this.selected,
      this.textStyle,
      this.tooltip,
      this.icon,
      this.data,
      this.backgroundColor,
      this.borderColor,
      this.borderWidth,
      this.borderRadius,
      this.shadowBlur,
      this.shadowColor,
      this.shadowOffsetX,
      this.shadowOffsetY,
      this.scrollDataIndex,
      this.pageButtonItemGap,
      this.pageButtonGap,
      this.pageButtonPosition,
      this.pageFormatter,
      this.pageIcons,
      this.pageIconColor,
      this.pageIconColorInactiveColor,
      this.pageIconSize,
      this.pageTextStyle,
      this.animation,
      this.animationDurationUpdate,
      this.emphasis,
      this.selector,
      this.selectorLabel,
      this.selectorPosition,
      this.selectorItemGap,
      this.selectorButtonGap});

  factory Legend.fromJson(Map<String, dynamic> json) =>
      _$LegendFromJson(json);
  Map<String, dynamic> toJson() => _$LegendToJson(this);
}
